class Node:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

    def __str__(self):
        return str(self.val)+'-->' if self.next else str(self.val)


class LinkList:

    def __init__(self, data):
        self.head = Node(data[0])
        current = self.head
        for index in range(1, len(data)):
            temp = Node(data[index])
            current.next = temp
            current = current.next

    def traverse(self):
        temp = self.head
        result=""
        while temp:
            result+=str(temp)
            temp = temp.next
        return result

    def search(self,value):
        current=self.head
        while current:
            if current.val==value:
                return True
            else:
                current=current.next
        return False

    def insert(self,data,data_after):
        node=Node(data)
        current=self.head
        while current:
            if current.val==data_after:
                node.next=current.next
                current.next=node
                break
            else:
                current=current.next

    def insert_head(self,data):
        node=Node(data)
        node.next=self.head
        self.head=node

    def replace(self,new,old):
        current=self.head
        while current:
            if current.val==old:
                current.val=new
            current=current.next

    def delete(self,old):
        if self.head.val==old:
            self.head=self.head.next
        pre=None
        current=self.head
        while current:
            if current.val==old:
                pre.next=current.next
                # current=current.next
            else:
                pre=current
                # current=current.next
            current=current.next



